/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_ora_push_ttc7_new_stmt.c                         */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/22 by geyh                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"

#include "../../../../src/module/oracle/config.h"
#include "../../test_ora_comm.h"
#include <apmtest_comm.h>
#include <oracle/comm/ora_stmt.h>

extern void test_ora_destroy_ct(Conntrack *p_st_conn);

extern int ora_push_ttc7_new_stmt(Conntrack *p_st_conn
        , Sql_statement **pp_st_stmt);

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(test_ora_create_ct(&p_st_conn, TEST_ORA_SRC_IP, TEST_ORA_DST_IP, TEST_ORA_SRC_PORT, TEST_ORA_DST_PORT), FR_SUCC);

    ora_clear_ttc7_new_stmt(p_st_conn);

    test_ora_destroy_ct(&p_st_conn);
    return;
}


static void __case2(void)
{
    Conntrack *p_st_conn = NULL;
    Sql_statement *p_st_stmt = NULL;
    int i_ret = 0;

    CU_ASSERT_EQUAL(test_ora_create_ct(&p_st_conn, TEST_ORA_SRC_IP, TEST_ORA_DST_IP, TEST_ORA_SRC_PORT, TEST_ORA_DST_PORT), FR_SUCC);

//    i_ret = ora_create_new_stmt(p_st_conn, &p_st_stmt);

    i_ret = ora_push_ttc7_new_stmt(p_st_conn, &p_st_stmt);

    CU_ASSERT_PTR_NOT_NULL(p_st_stmt);
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    ora_clear_ttc7_new_stmt(p_st_conn);

    test_ora_destroy_ct(&p_st_conn);
    return;
}


int add_suite_ora_clear_ttc7_new_stmt(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" ora_clear_ttc7_new_stmt()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);

    return FR_SUCC;
}
